<?php

namespace backend\modules\business\controllers;

use backend\controllers\AdminController;
use common\components\Upload;
use common\models\business\BusinessContractCategory;
use common\models\business\BusinessContractField;
use common\models\business\BusinessContractFieldvalue;
use Yii;
use common\models\business\BusinessContract;
use backend\modules\business\models\BusinessContractSearch;
use yii\db\Query;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
 * 合同往来汇总
 */
class ContractTcombackController extends AdminController
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }

    /**
     * Lists all BusinessContract models.
     * @return mixed
     */
    public function actionIndex()
    {
        $searchModel = new BusinessContractSearch();
        $params['BusinessContractSearch'] =  ['htwlshow'=>1];
        $params = array_merge_recursive($params,Yii::$app->request->queryParams);
        $dataProvider = $searchModel->search($params);

        return $this->render('index', [
            'searchModel' => $searchModel,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * Displays a single BusinessContract model.
     * @param string $id
     * @return mixed
     */
    public function actionView($id)
    {
        $model = $this->findModel($id);
        $showpre = BusinessContractCategory::showPre(BusinessContractCategory::findOne($model->cateid));


        return $this->render('view', [
            'model' => $this->findModel($id),
            'showpre' => $showpre
        ]);
    }


    /**
     * Finds the BusinessContract model based on its primary key value.
     * If the model is not found, a 404 HTTP exception will be thrown.
     * @param string $id
     * @return BusinessContract the loaded model
     * @throws NotFoundHttpException if the model cannot be found
     */
    protected function findModel($id)
    {
        if (($model = BusinessContract::findOne($id)) !== null) {
            return $model;
        } else {
            throw new NotFoundHttpException('The requested page does not exist.');
        }
    }
}
